package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.CureTaskCourseDAO;
import cn.edu.scau.cmi.hombio.dao.CureTaskMedicineDAO;
import cn.edu.scau.cmi.hombio.dao.CureTaskMethodDAO;
import cn.edu.scau.cmi.hombio.dao.CureTypeDAO;

import cn.edu.scau.cmi.hombio.domain.CureTaskCourse;
import cn.edu.scau.cmi.hombio.domain.CureTaskMedicine;
import cn.edu.scau.cmi.hombio.domain.CureTaskMethod;
import cn.edu.scau.cmi.hombio.domain.CureType;

import cn.edu.scau.cmi.hombio.service.CureTaskMethodService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for CureTaskMethod entities
 * 
 */

@Controller("CureTaskMethodRestController")

public class CureTaskMethodRestController {

	/**
	 * DAO injected by Spring that manages CureTaskCourse entities
	 * 
	 */
	@Autowired
	private CureTaskCourseDAO cureTaskCourseDAO;

	/**
	 * DAO injected by Spring that manages CureTaskMedicine entities
	 * 
	 */
	@Autowired
	private CureTaskMedicineDAO cureTaskMedicineDAO;

	/**
	 * DAO injected by Spring that manages CureTaskMethod entities
	 * 
	 */
	@Autowired
	private CureTaskMethodDAO cureTaskMethodDAO;

	/**
	 * DAO injected by Spring that manages CureType entities
	 * 
	 */
	@Autowired
	private CureTypeDAO cureTypeDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for CureTaskMethod entities
	 * 
	 */
	@Autowired
	private CureTaskMethodService cureTaskMethodService;

	/**
	 * Create a new CureTaskMethod entity
	 * 
	 */
	@RequestMapping(value = "/CureTaskMethod", method = RequestMethod.POST)
	@ResponseBody
	public CureTaskMethod newCureTaskMethod(@RequestBody CureTaskMethod curetaskmethod) {
		cureTaskMethodService.saveCureTaskMethod(curetaskmethod);
		return cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethod.getId());
	}

	/**
	* Delete an existing CureTaskMedicine entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureTaskMedicines/{curetaskmedicine_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskMethodCureTaskMedicines(@PathVariable Integer curetaskmethod_id, @PathVariable Integer related_curetaskmedicines_id) {
		cureTaskMethodService.deleteCureTaskMethodCureTaskMedicines(curetaskmethod_id, related_curetaskmedicines_id);
	}

	/**
	* Create a new CureType entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureType", method = RequestMethod.POST)
	@ResponseBody
	public CureType newCureTaskMethodCureType(@PathVariable Integer curetaskmethod_id, @RequestBody CureType curetype) {
		cureTaskMethodService.saveCureTaskMethodCureType(curetaskmethod_id, curetype);
		return cureTypeDAO.findCureTypeByPrimaryKey(curetype.getId());
	}

	/**
	* Show all CureTaskMedicine entities by CureTaskMethod
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureTaskMedicines", method = RequestMethod.GET)
	@ResponseBody
	public List<CureTaskMedicine> getCureTaskMethodCureTaskMedicines(@PathVariable Integer curetaskmethod_id) {
		return new java.util.ArrayList<CureTaskMedicine>(cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethod_id).getCureTaskMedicines());
	}

	/**
	* Delete an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskMethod(@PathVariable Integer curetaskmethod_id) {
		CureTaskMethod curetaskmethod = cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethod_id);
		cureTaskMethodService.deleteCureTaskMethod(curetaskmethod);
	}

	/**
	* Save an existing CureTaskCourse entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureTaskCourse", method = RequestMethod.PUT)
	@ResponseBody
	public CureTaskCourse saveCureTaskMethodCureTaskCourse(@PathVariable Integer curetaskmethod_id, @RequestBody CureTaskCourse curetaskcourse) {
		cureTaskMethodService.saveCureTaskMethodCureTaskCourse(curetaskmethod_id, curetaskcourse);
		return cureTaskCourseDAO.findCureTaskCourseByPrimaryKey(curetaskcourse.getId());
	}

	/**
	* View an existing CureType entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureType/{curetype_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureType loadCureTaskMethodCureType(@PathVariable Integer curetaskmethod_id, @PathVariable Integer related_curetype_id) {
		CureType curetype = cureTypeDAO.findCureTypeByPrimaryKey(related_curetype_id, -1, -1);

		return curetype;
	}

	/**
	* Create a new CureTaskMedicine entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureTaskMedicines", method = RequestMethod.POST)
	@ResponseBody
	public CureTaskMedicine newCureTaskMethodCureTaskMedicines(@PathVariable Integer curetaskmethod_id, @RequestBody CureTaskMedicine curetaskmedicine) {
		cureTaskMethodService.saveCureTaskMethodCureTaskMedicines(curetaskmethod_id, curetaskmedicine);
		return cureTaskMedicineDAO.findCureTaskMedicineByPrimaryKey(curetaskmedicine.getId());
	}

	/**
	* Show all CureTaskMethod entities
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod", method = RequestMethod.GET)
	@ResponseBody
	public List<CureTaskMethod> listCureTaskMethods() {
		return new java.util.ArrayList<CureTaskMethod>(cureTaskMethodService.loadCureTaskMethods());
	}

	/**
	* Save an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod", method = RequestMethod.PUT)
	@ResponseBody
	public CureTaskMethod saveCureTaskMethod(@RequestBody CureTaskMethod curetaskmethod) {
		cureTaskMethodService.saveCureTaskMethod(curetaskmethod);
		return cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethod.getId());
	}

	/**
	* Delete an existing CureTaskCourse entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureTaskCourse/{curetaskcourse_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskMethodCureTaskCourse(@PathVariable Integer curetaskmethod_id, @PathVariable Integer related_curetaskcourse_id) {
		cureTaskMethodService.deleteCureTaskMethodCureTaskCourse(curetaskmethod_id, related_curetaskcourse_id);
	}

	/**
	* Get CureTaskCourse entity by CureTaskMethod
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureTaskCourse", method = RequestMethod.GET)
	@ResponseBody
	public CureTaskCourse getCureTaskMethodCureTaskCourse(@PathVariable Integer curetaskmethod_id) {
		return cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethod_id).getCureTaskCourse();
	}

	/**
	* Save an existing CureTaskMedicine entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureTaskMedicines", method = RequestMethod.PUT)
	@ResponseBody
	public CureTaskMedicine saveCureTaskMethodCureTaskMedicines(@PathVariable Integer curetaskmethod_id, @RequestBody CureTaskMedicine curetaskmedicines) {
		cureTaskMethodService.saveCureTaskMethodCureTaskMedicines(curetaskmethod_id, curetaskmedicines);
		return cureTaskMedicineDAO.findCureTaskMedicineByPrimaryKey(curetaskmedicines.getId());
	}

	/**
	* Create a new CureTaskCourse entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureTaskCourse", method = RequestMethod.POST)
	@ResponseBody
	public CureTaskCourse newCureTaskMethodCureTaskCourse(@PathVariable Integer curetaskmethod_id, @RequestBody CureTaskCourse curetaskcourse) {
		cureTaskMethodService.saveCureTaskMethodCureTaskCourse(curetaskmethod_id, curetaskcourse);
		return cureTaskCourseDAO.findCureTaskCourseByPrimaryKey(curetaskcourse.getId());
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* View an existing CureTaskCourse entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureTaskCourse/{curetaskcourse_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureTaskCourse loadCureTaskMethodCureTaskCourse(@PathVariable Integer curetaskmethod_id, @PathVariable Integer related_curetaskcourse_id) {
		CureTaskCourse curetaskcourse = cureTaskCourseDAO.findCureTaskCourseByPrimaryKey(related_curetaskcourse_id, -1, -1);

		return curetaskcourse;
	}

	/**
	* Save an existing CureType entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureType", method = RequestMethod.PUT)
	@ResponseBody
	public CureType saveCureTaskMethodCureType(@PathVariable Integer curetaskmethod_id, @RequestBody CureType curetype) {
		cureTaskMethodService.saveCureTaskMethodCureType(curetaskmethod_id, curetype);
		return cureTypeDAO.findCureTypeByPrimaryKey(curetype.getId());
	}

	/**
	* Select an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureTaskMethod loadCureTaskMethod(@PathVariable Integer curetaskmethod_id) {
		return cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethod_id);
	}

	/**
	* Get CureType entity by CureTaskMethod
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureType", method = RequestMethod.GET)
	@ResponseBody
	public CureType getCureTaskMethodCureType(@PathVariable Integer curetaskmethod_id) {
		return cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethod_id).getCureType();
	}

	/**
	* Delete an existing CureType entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureType/{curetype_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskMethodCureType(@PathVariable Integer curetaskmethod_id, @PathVariable Integer related_curetype_id) {
		cureTaskMethodService.deleteCureTaskMethodCureType(curetaskmethod_id, related_curetype_id);
	}

	/**
	* View an existing CureTaskMedicine entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMethod/{curetaskmethod_id}/cureTaskMedicines/{curetaskmedicine_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureTaskMedicine loadCureTaskMethodCureTaskMedicines(@PathVariable Integer curetaskmethod_id, @PathVariable Integer related_curetaskmedicines_id) {
		CureTaskMedicine curetaskmedicine = cureTaskMedicineDAO.findCureTaskMedicineByPrimaryKey(related_curetaskmedicines_id, -1, -1);

		return curetaskmedicine;
	}
}